﻿namespace EasyGo.Utils.Navigation
{
    using System;
    using System.Collections.Generic;
    using EasyGo.Common.Auth;

    public class MenuItem
    {
        public string Name { get; set; }

        public string ViewName { get; set; }

        public string Title { get; set; }

        public IList<MenuItem> Childs { get; set; }

        public UserRole[] RolesEnabled { get; set; }

        public static MenuItem Create(string name, string viewName, string title = null, UserRole[] rolesEnabled = null, params MenuItem[] childs)
        {
            var item = new MenuItem();
            item.Name = name;
            item.Title = title ?? name;
            item.ViewName = viewName;
            foreach (var menuItem in childs)
            {
                item.AddChild(menuItem);
            }

            item.RolesEnabled = rolesEnabled ?? new[] { UserRole.Admin, UserRole.Worker, UserRole.Customer };

            return item;
        }

        public void AddChild(MenuItem item)
        {
            this.Childs.Add(item);
        }
    }
}